package ${packageName}.service.impl;

import ${packageName}.entity.${tableInfo.className};
import ${packageName}.mapper.${tableInfo.className}Mapper;
import ${packageName}.service.${tableInfo.className}Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sssre.lttcloud.common.result.Result;
import com.sssre.lttcloud.common.result.ResultCode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ${tableInfo.tableComment}服务实现类
 * 
 * @author ${tableInfo.author}
 * @date ${.now?string("yyyy-MM-dd")}
 */
@Service
public class ${tableInfo.className}ServiceImpl extends ServiceImpl<${tableInfo.className}Mapper, ${tableInfo.className}> implements ${tableInfo.className}Service {

    @Override
    public Result<${tableInfo.className}> save${tableInfo.className}(${tableInfo.className} ${tableInfo.className?uncap_first}) {
        try {
            boolean success = this.save(${tableInfo.className?uncap_first});
            return success ? Result.success(${tableInfo.className?uncap_first}) : Result.error(ResultCode.OPERATION_FAILED);
        } catch (Exception e) {
            return Result.error(ResultCode.SYSTEM_ERROR);
        }
    }

    @Override
    public Result<${tableInfo.className}> get${tableInfo.className}ById(Long id) {
        try {
            ${tableInfo.className} ${tableInfo.className?uncap_first} = this.getById(id);
            if (${tableInfo.className?uncap_first} == null) {
                return Result.error(ResultCode.DATA_NOT_FOUND);
            }
            return Result.success(${tableInfo.className?uncap_first});
        } catch (Exception e) {
            return Result.error(ResultCode.SYSTEM_ERROR);
        }
    }

    @Override
    public Result<List<${tableInfo.className}>> getAll${tableInfo.className}s() {
        try {
            List<${tableInfo.className}> list = this.list();
            return Result.success(list);
        } catch (Exception e) {
            return Result.error(ResultCode.SYSTEM_ERROR);
        }
    }

    @Override
    public Result<IPage<${tableInfo.className}>> get${tableInfo.className}Page(Page<${tableInfo.className}> page) {
        try {
            IPage<${tableInfo.className}> result = this.page(page);
            return Result.success(result);
        } catch (Exception e) {
            return Result.error(ResultCode.SYSTEM_ERROR);
        }
    }

    @Override
    public Result<String> delete${tableInfo.className}ById(Long id) {
        try {
            boolean success = this.removeById(id);
            return success ? Result.success("删除成功") : Result.error(ResultCode.OPERATION_FAILED);
        } catch (Exception e) {
            return Result.error(ResultCode.SYSTEM_ERROR);
        }
    }

    @Override
    public Result<String> delete${tableInfo.className}Batch(List<Long> ids) {
        try {
            boolean success = this.removeByIds(ids);
            return success ? Result.success("批量删除成功") : Result.error(ResultCode.OPERATION_FAILED);
        } catch (Exception e) {
            return Result.error(ResultCode.SYSTEM_ERROR);
        }
    }
} 